<template>
  <div class="search">
    <f-form ref="form" :action="api.bmp" :form-key="this.formItem.materialId">
      <f-form-item label="项目" type="select" name="projectId" :showSearch="true"
                   :data="api.bmp.projectList" label-key="projectName" value-key="projectId"
                   :value="formItem.projectId" :disabled="true"/>
      <f-form-item label="指令号" name="instructNumber" :value="formItem.instructNumber" v-if="isAdd && type==2"/>
      <f-form-item label="工程包代码" name="packageNo" :value="formItem.packageNo" :readOnly="true"/>
      <f-form-item label="工程包名称" name="packageName" :value="formItem.packageName" :readOnly="true"/>
      <f-form-item label="专业代码" name="majorCode" :value="formItem.majorCode" :readOnly="true"/>
      <f-form-item label="专业包名称" name="majorName" :value="formItem.majorName" :readOnly="true"/>
      <f-form-item label="服务代码" type="pageSelect" name="serviceCode" :showSearch="true"
                   :data="api.service.page" label-key="serviceCode,serviceName" value-key="serviceCode"
                   :value="formItem.serviceCode" :params="{}"/>
      <f-form-item label="服务WBS代码" type="pageSelect" name="serviceWbsCode" :showSearch="true"
                   :data="api.wbsarchitecture.page" label-key="wbsCode" value-key="wbsCode"
                   :value="formItem.serviceWbsCode" :params="{}"/>
      <f-form-item label="项目（名称）" name="materiaSpecs" :value="formItem.materiaSpecs"/>
      <f-form-item label="科目名称" name="subjectName" :value="formItem.subjectName"/>
      <f-form-item label="层级号" name="levelNo" :value="formItem.levelNo"/>
      <f-form-item label="分承包发包项目描述" name="packageDesc" :value="formItem.packageDesc"/>
      <f-form-item label="对外合同描述" name="contractDesc" :value="formItem.contractDesc"/>
      <f-form-item label="区域" name="materialArea" :value="formItem.materialArea"/>
      <f-form-item label="系统" name="materialUse" :value="formItem.materialUse"/>
      <f-form-item label="100预算成本工程量" name="costQuantity100" :value="formItem.costQuantity100"/>
    </f-form>
  </div>
</template>
<script>
  import api from './js/api'
  import apiOther from './js/apiOther'

  export default {
    name: 'materialForm',
    props: {
      type: ''
    },
    data() {
      return {
        refs: this.$refs,
        api: Object.assign(api, apiOther, this.api),
        isAdd: true,//是否是添加模式
        loaded: false,//是否加载完成
        formItem: this.getFormItem()
      }
    },
    methods: {
      getFormItem() {
        return {
          materialId: '',
          parentId: 0,
          projectId: '',
          packageNo: '',
          packageName: '',
          majorCode: '',
          majorName: '',
          serviceCode: '',
          serviceWbsCode: '',
          materiaSpecs: '',
          subjectName: '',
          levelNo: '',
          packageDesc: '',
          contractDesc: '',
          materialArea: '',
          materialUse: '',
          costQuantity100: '',
          status: '',
          instructNumber: ''
        }
      },
      //表单赋值
      setData(data) {
        this.$refs.form.resetFields()
        this.formItem = this.getFormItem()
        this.formItem.projectId = data.projectId
        this.formItem.packageNo = data.packageNo
        this.formItem.packageName = data.packageName
        this.formItem.majorCode = data.majorCode
        this.formItem.majorName = data.majorName
        if (data && data.materialId) {
          let params = {
            materialId: data.materialId
          }
          this.refs['form'].getDetails(params, (data) => {
            this.formItem = data
            this.loaded = true
          })
          this.isAdd = false
        } else {
          this.loaded = true
        }
      },
      //提交表单
      handleSubmit(callback) {
        this.$refs.form.submit({ handlerName: 'busMaterialPackage100SaveHandler' }, this.registerListener())
      },
      registerListener() {
        this.$bus.emit('refreshDetailsMaterialPackage100')
      }
    },
    created() {
    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
